package com.ruoyi.znjc.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.znjc.mapper.ZnjcMessagesMapper;
import com.ruoyi.znjc.domain.ZnjcMessages;
import com.ruoyi.znjc.service.IZnjcMessagesService;
import com.ruoyi.znjc.mapper.ZnjcConversationsMapper;


/**
 * 消息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-26
 */
@Service
public class ZnjcMessagesServiceImpl implements IZnjcMessagesService 
{
    @Autowired
    private ZnjcMessagesMapper znjcMessagesMapper;

    /**
     * 查询消息
     * 
     * @param messageId 消息主键
     * @return 消息
     */
    @Override
    public ZnjcMessages selectZnjcMessagesByMessageId(Long messageId)
    {
        return znjcMessagesMapper.selectZnjcMessagesByMessageId(messageId);
    }

    /**
     * 查询消息列表
     * 
     * @param znjcMessages 消息
     * @return 消息
     */
    @Override
    public List<ZnjcMessages> selectZnjcMessagesList(ZnjcMessages znjcMessages)
    {
        return znjcMessagesMapper.selectZnjcMessagesList(znjcMessages);
    }

    /**
     * 新增消息
     * 
     * @param znjcMessages 消息
     * @return 结果
     */
    @Override
    public int insertZnjcMessages(ZnjcMessages znjcMessages)
    {
        int rows = znjcMessagesMapper.insertZnjcMessages(znjcMessages);

        // 添加：插入消息后更新会话的更新时间
        if (znjcMessages.getConversationId() != null) {
            znjcConversationsMapper.updateConversationTime(znjcMessages.getConversationId());
        }

        return rows;
    }

    /**
     * 修改消息
     * 
     * @param znjcMessages 消息
     * @return 结果
     */
    @Override
    public int updateZnjcMessages(ZnjcMessages znjcMessages)
    {
        return znjcMessagesMapper.updateZnjcMessages(znjcMessages);
    }

    /**
     * 批量删除消息
     * 
     * @param messageIds 需要删除的消息主键
     * @return 结果
     */
    @Override
    public int deleteZnjcMessagesByMessageIds(Long[] messageIds)
    {
        return znjcMessagesMapper.deleteZnjcMessagesByMessageIds(messageIds);
    }

    /**
     * 删除消息信息
     * 
     * @param messageId 消息主键
     * @return 结果
     */
    @Override
    public int deleteZnjcMessagesByMessageId(Long messageId)
    {
        return znjcMessagesMapper.deleteZnjcMessagesByMessageId(messageId);
    }


    @Autowired
    private ZnjcConversationsMapper znjcConversationsMapper;

    @Override
    public List<ZnjcMessages> selectMessagesByConversationId(Long conversationId) {
        return znjcMessagesMapper.selectMessagesByConversationId(conversationId);
    }





}
